function newLi(name,params) {
  var li = document.createElement("li");
  $("mainList").appendChild(li);
  var a = document.createElement("a");
  li.appendChild(a);
  if (params) {
    if (params != true) {
      a.href = newLocation(params);
    }
    li.className = "page_item page-item-2";
  } else {
    a.href = "#";
    li.className = "page_item";
  }
  a.title = name;
  a.innerHTML = name;
  return a;
}

function resetHost() {
  var loc = document.location + "";
  loc = loc.replace(/host=\d+\.\d+\.\d+\.\d+/,'');
  if (!loc.match(/.*host\=\w+.*/)) {
    document.location = BASE + "?host=" + $("host").value;
  }
}

function loadResetHost() {
  var li = document.createElement("li");
  $("mainList").appendChild(li);
  li.className = "page_item page-item-2";
  var a = document.createElement("a");
  li.appendChild(a);
  a.href = "#";
  a.onclick = resetHost;
  a.title = "Set host";
  a.innerHTML = "Set host";
  var input = document.createElement("input");
  input.id = "host";
  input.value = host;
  li.appendChild(input);
}

addEventListener("load", function()
                 {
                   setTimeout(updateLayout, 0);
                 }, false);

var currentWidth = 0;
      
function updateLayout()
{
  if (window.innerWidth != currentWidth)
    {
      currentWidth = window.innerWidth;

      var orient = currentWidth == 320 ? "profile" : "landscape";
      document.body.setAttribute("orient", orient);
      setTimeout(function()
                 {
                   window.scrollTo(0, 1);
                 }, 100);            
    }
}

setInterval(updateLayout, 400);
